package cn.com.greatwall.flowable.service.mapstruct;

import java.util.ArrayList;
import java.util.List;

import org.flowable.engine.FormService;
import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.stereotype.Component;

import cn.com.greatwall.common.base.BaseMapper;
import cn.com.greatwall.flowable.service.dto.ProcessDefinitionDto;
import lombok.RequiredArgsConstructor;

/**
 * @Author herw
 * @Time 2020-11-17 14:47:56
 * @Version 1.0
 * @Description: TODO(用一句话描述该文件做什么)
 */
@Component
@RequiredArgsConstructor
public class ProcessDefinitionMapper implements BaseMapper<ProcessDefinitionDto, ProcessDefinition> {
    private final FormService formService;
    
    @Override
    public ProcessDefinition toEntity(ProcessDefinitionDto dto) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public ProcessDefinitionDto toDto(ProcessDefinition entity) {
        ProcessDefinitionDto dto = new ProcessDefinitionDto();
        dto.setId(entity.getId());
        dto.setKey(entity.getKey());
        dto.setVersion(entity.getVersion());
        dto.setCategory(entity.getCategory());
        dto.setName(entity.getName());
        dto.setDescription(entity.getDescription());
        dto.setSuspended(entity.isSuspended());
        dto.setGraphicalNotationDefined(entity.hasGraphicalNotation());
        dto.setTenantId(entity.getTenantId());
        dto.setFormKey(entity.hasStartFormKey() ? formService.getStartFormKey(entity.getId()) : null);
        
        return dto;
    }

    @Override
    public List<ProcessDefinition> toEntity(List<ProcessDefinitionDto> dtoList) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<ProcessDefinitionDto> toDto(List<ProcessDefinition> entityList) {
        List<ProcessDefinitionDto> dtoList = new ArrayList<>();
        for (ProcessDefinition instance : entityList) {
            dtoList.add(toDto(instance));
        }
        return dtoList;
    }

}
